<template>
  <div class="brand-box">
    <div class="title">
      <span></span>
      <h6 v-if="!errType">查看模板</h6>
      <h6 v-if="errType">错误提示</h6>
      <span></span>
    </div>
    <div class="explain-text">
      <p v-show="errType">
        <span>{{msgText}}</span>
      </p>
    </div>
    <div class="img-box" v-if="!errType">
      <img :src="require('../assets/img/' + imgType + '.png')" alt="">
    </div>
    <div class="qrcode-box" v-if="errType && wxqr">
      <img :src="wxqr" alt="微信客服二维码">
      <p>微信客服二维码</p>
    </div>
    <div class="contact" v-show="errType">
      <div @click="onConsultation" v-if="qq">
        <span class="qq-icon"></span>
        <span>在线QQ咨询</span>
      </div>
      <div @click="onTel">
        <img src="../assets/img/kf.png" alt="">
        <span>{{tel}}</span>
      </div>
    </div>
    <div class="close" @click="closeTemplate">
      <p :style="{'height': height, 'line-height': height}">我知道了</p>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex'
export default {
  props: {
    imgType: {
      type: String,
      default: ''
    },
    errType: {
      type: Boolean,
      default: false
    },
    msgText: {
      type: String,
      default: '品牌推荐内容有误，请仔细检查并重新填写！'
    }
  },
  data() {
    return {
      isPhone: false
    }
  },
  computed: {
    ...mapState({
      catName: s => s.catName,
      qq: s => s.serviceInfo.qq,
      tel: s => s.serviceInfo.tel,
      wxqr: s => s.serviceInfo.wxqr
    }),
    height() {
      if (this.msgText.length <= 18) {
        return '1.22rem'
      } else {
        return '0.88rem'
      }
    }
  },
  created() {
    this.isPhone = this.$getDeviceInfo().isPhone
  },
  methods: {
    closeTemplate() {
      this.$emit('onClose', false)
    },
    onConsultation() {
      window.location.href = 'http://wpa.qq.com/msgrd?v=3&uin=' + this.qq + '&site=qq&menu=yes'
    },
    onTel() {
      if (this.isPhone) {
        window.location.href = 'tel:' + this.tel
      }
    }
  }
}
</script>
<style lang='scss' scoped>
.brand-box {
  width: 6rem;
  // height: 9rem;
  border-radius: 0.1rem;
  background: #fff;
  .title {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 0.56rem;
    h6 {
      font-size: 0.32rem;
      color: rgba(51, 51, 51, 1);
      margin: 0 0.4rem;
    }
    span {
      width: 1.2rem;
      height: 1px;
      background-color: rgba(223, 223, 223, 1);
    }
  }
  .explain-text {
    margin: 0.5rem 0 0.3rem;
    padding: 0 0.66rem;
    p {
      text-align: center;
      span {
        font-size: 0.26rem;
        line-height: 0.34rem;
        color: rgba(153, 153, 153, 1);
        display: inline-block;
        text-align: left;
      }
    }
  }
  .img-box {
    margin-bottom: 0.56rem;
    text-align: center;
    img {
      width: 3.34rem;
      height: 4.96rem;
    }
  }
  .qrcode-box {
    text-align: center;
    p {
      font-size: 0.28rem;
      color: rgba(153, 153, 153, 1);
      line-height: 0.42rem;
    }
    img {
      width: 2.5rem;
      height: 2.5rem;
      padding: 0.3rem;
    }
  }
  .contact {
    display: flex;
    justify-content: space-around;
    align-items: center;
    position: absolute;
    bottom: 0.88rem;
    left: 0;
    right: 0;
    margin: 0.5rem 0;
    div {
      span {
        font-size: 0.34rem;
        color: rgba(115, 158, 251, 1);
        vertical-align: middle;
      }
      .qq-icon {
        display: inline-block;
        vertical-align: middle;
        width: 0.5rem;
        height: 0.5rem;
        background: url("../assets/img/qq.png") center no-repeat;
        background-size: cover;
        margin-right: 0.14rem;
      }
      img {
        margin-right: 0.14rem;
        width: 0.26rem;
        height: auto;
        vertical-align: bottom;
      }
      // .phone-icon {
      //   display: inline-block;
      //   vertical-align: middle;
      //   width: 0.3rem;
      //   height: 0.3rem;
      //   background: url("../assets/img/kf.png") center no-repeat;
      //   background-size: contain;
      //   margin-right: 0.14rem;
      // }
    }
  }
  .close {
    width: 100%;
    border-top: 1px solid rgba(204, 204, 204, 1);
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    cursor: pointer;
    p {
      height: 0.88rem;
      line-height: 0.88rem;
      text-align: center;
      font-size: 0.3rem;
    }
  }
}
</style>
